package com.example.day09.exercise;

import java.util.ArrayList;
import java.util.List;

public class ArrayExercise {
    public static void main(String[] args) {
        List<Integer> lis1=new ArrayList<>();
        ArrayList<Book> list=new ArrayList<>();

        Book b1=new Book(1,"java",100.0d);
        Book b2=new Book(2,"java script",200.0d);
        Book b3=new Book(3,"python",300.0d);
        Book b4=new Book(4,"go",400.0d);
        Book b5=new Book(5,"go",500.0d);

        list.add(b1);
        list.add(b2);
        list.add(b3);
        list.add(b4);
        list.add(b5);
        System.out.println(list);
//        for (int i = 0; i < list.size(); i++) {
//            if(list.get(i).getName().equals("java")){
//                list.remove(list.get(i)); //数组元素前移   i要减减
//                i--;
//            }
//        }

        delByname(list,"java");

        System.out.println(list);
    }

    private static void delByname(ArrayList<Book> list, String name) {

        if(list!=null && list.size()>0){
            for (int i = 0; i < list.size(); i++) {
                if(list.get(i).getName().indexOf(name)!=-1){
                    list.remove(i);
                    i--;
                }
            }
        }
    }
}
